From: Jyrki Gadinger Date: Fri, 10 Jan 2025 12:53:17 +0000 (+0100) Subject: fetch "shared with me" information separately X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~2^2~86^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=269378e08136c21ddc4cbefb9c4710d8563d1897;p=nextcloud-desktop.git fetch "shared with me" information separately if the parameter `shared_with_me` is set to `"true"` on the shares API call the response will only include that and not return any other sharing information. therefore let's fetch it inside another job (this is also how the web client does it). Signed-off-by: Jyrki Gadinger --- diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index b7336c0c8..e3be7122a 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -363,6 +363,7 @@ void ShareModel::initShareManager() if (_manager.isNull() && sharingPossible) { _manager.reset(new ShareManager(_accountState->account(), this)); connect(_manager.data(), &ShareManager::sharesFetched, this, &ShareModel::slotSharesFetched); + connect(_manager.data(), &ShareManager::sharedWithMeFetched, this, &ShareModel::slotSharedWithMeFetched); connect(_manager.data(), &ShareManager::shareCreated, this, [&] { _manager->fetchShares(_sharePath); }); @@ -379,6 +380,7 @@ void ShareModel::initShareManager() }); _manager->fetchShares(_sharePath); + _manager->fetchSharedWithMe(_sharePath); } } @@ -493,38 +495,13 @@ void ShareModel::slotSharesFetched(const QList &shares) qCInfo(lcSharing) << "Fetched" << shares.count() << "shares"; for (const auto &share : shares) { - if (share.isNull()) { + if (share.isNull() || + share->account().isNull() || + share->getUidOwner() != share->account()->davUser()) { continue; - } else if (const auto selfUserId = share->account()->davUser(); share->getUidOwner() != selfUserId) { - _displayShareOwner = true; - Q_EMIT displayShareOwnerChanged(); - _shareOwnerDisplayName = share->getOwnerDisplayName(); - Q_EMIT shareOwnerDisplayNameChanged(); - _shareOwnerAvatar = "image://avatars/user-id=" - + share->getUidOwner() - + "/local-account:" - + share->account()->displayName(); - Q_EMIT shareOwnerAvatarChanged(); - - if (share->getShareType() == Share::TypeUser && - share->getShareWith() && - share->getShareWith()->shareWith() == selfUserId) - { - const auto userShare = share.objectCast(); - const auto expireDate = userShare->getExpireDate(); - const auto daysToExpire = QDate::currentDate().daysTo(expireDate); - _sharedWithMeExpires = expireDate.isValid(); - Q_EMIT sharedWithMeExpiresChanged(); - _sharedWithMeRemainingTimeString = daysToExpire > 1 - ? tr("%1 days").arg(daysToExpire) - : daysToExpire > 0 - ? tr("1 day") - : tr("Today"); - Q_EMIT sharedWithMeRemainingTimeStringChanged(); - } - } else { - slotAddShare(share); } + + slotAddShare(share); } // Perform forward pass on shares and check for duplicate display names; store these indeces so @@ -565,6 +542,47 @@ void ShareModel::slotSharesFetched(const QList &shares) handleLinkShare(); } +void ShareModel::slotSharedWithMeFetched(const QList &shares) +{ + qCInfo(lcSharing) << "Fetched" << shares.count() << "shares that have been shared_with_me"; + + for (const auto &share : shares) { + if (share.isNull()) { + continue; + } + + const auto selfUserId = share->account()->davUser(); + if (share->getUidOwner() == selfUserId) { + continue; + } + + _displayShareOwner = true; + Q_EMIT displayShareOwnerChanged(); + _shareOwnerDisplayName = share->getOwnerDisplayName(); + Q_EMIT shareOwnerDisplayNameChanged(); + _shareOwnerAvatar = QStringLiteral("image://avatars/user-id=%1/local-account:%2") + .arg(share->getUidOwner(), share->account()->displayName()); + Q_EMIT shareOwnerAvatarChanged(); + + if (share->getShareType() == Share::TypeUser && + share->getShareWith() && + share->getShareWith()->shareWith() == selfUserId) + { + const auto userShare = share.objectCast(); + const auto expireDate = userShare->getExpireDate(); + const auto daysToExpire = QDate::currentDate().daysTo(expireDate); + _sharedWithMeExpires = expireDate.isValid(); + Q_EMIT sharedWithMeExpiresChanged(); + _sharedWithMeRemainingTimeString = daysToExpire > 1 + ? tr("%1 days").arg(daysToExpire) + : daysToExpire == 1 + ? tr("1 day") + : tr("Today"); + Q_EMIT sharedWithMeRemainingTimeStringChanged(); + } + } +} + void ShareModel::setupInternalLinkShare() { if (!_accountState || diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index e34dece4b..12b262bde 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -219,6 +219,7 @@ private slots: void slotAddShare(const OCC::SharePtr &share); void slotRemoveShareWithId(const QString &shareId); void slotSharesFetched(const QList &shares); + void slotSharedWithMeFetched(const QList &shares); void slotAddSharee(const OCC::ShareePtr &sharee); void slotRemoveSharee(const OCC::ShareePtr &sharee); diff --git a/src/gui/ocssharejob.cpp b/src/gui/ocssharejob.cpp index 3f2236c3e..eb69505b2 100644 --- a/src/gui/ocssharejob.cpp +++ b/src/gui/ocssharejob.cpp @@ -34,7 +34,6 @@ void OcsShareJob::getShares(const QString &path, const QMap &p addParam(QString::fromLatin1("path"), path); addParam(QString::fromLatin1("reshares"), QStringLiteral("true")); - addParam(QString::fromLatin1("shared_with_me"), QStringLiteral("true")); for (auto it = std::cbegin(params); it != std::cend(params); ++it) { addParam(it.key(), it.value()); @@ -208,10 +207,13 @@ void OcsShareJob::createShare(const QString &path, start(); } -void OcsShareJob::getSharedWithMe() +void OcsShareJob::getSharedWithMe(const QString &path) { setVerb("GET"); - addParam(QLatin1String("shared_with_me"), QLatin1String("true")); + + addParam(QString::fromLatin1("path"), path); + addParam(QString::fromLatin1("shared_with_me"), QStringLiteral("true")); + start(); } diff --git a/src/gui/ocssharejob.h b/src/gui/ocssharejob.h index 2abaf80a4..71e0883a7 100644 --- a/src/gui/ocssharejob.h +++ b/src/gui/ocssharejob.h @@ -135,8 +135,9 @@ public: /** * Returns information on the items shared with the current user. + * @param path Path to request shares for (default all shares) */ - void getSharedWithMe(); + void getSharedWithMe(const QString &path = ""); static const QString _pathForSharesRequest; diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index d025d629f..8065db43d 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -536,13 +536,21 @@ void ShareManager::slotShareCreated(const QJsonDocument &reply) void ShareManager::fetchShares(const QString &path) { - auto *job = new OcsShareJob(_account); + const auto job = new OcsShareJob(_account); connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharesFetched); connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError); job->getShares(path); } -void ShareManager::slotSharesFetched(const QJsonDocument &reply) +void ShareManager::fetchSharedWithMe(const QString &path) +{ + const auto sharedWithMeJob = new OcsShareJob(_account); + connect(sharedWithMeJob, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharedWithMeFetched); + connect(sharedWithMeJob, &OcsJob::ocsError, this, &ShareManager::slotOcsError); + sharedWithMeJob->getSharedWithMe(path); +} + +const QList ShareManager::parseShares(const QJsonDocument &reply) const { qDebug() << reply; auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray(); @@ -570,10 +578,22 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply) } qCDebug(lcSharing) << "Sending " << shares.count() << "shares"; + return shares; +} + +void ShareManager::slotSharesFetched(const QJsonDocument &reply) +{ + const auto shares = parseShares(reply); emit sharesFetched(shares); } -QSharedPointer ShareManager::parseUserGroupShare(const QJsonObject &data) +void ShareManager::slotSharedWithMeFetched(const QJsonDocument &reply) +{ + const auto shares = parseShares(reply); + emit sharedWithMeFetched(shares); +} + +QSharedPointer ShareManager::parseUserGroupShare(const QJsonObject &data) const { ShareePtr sharee(new Sharee(data.value("share_with").toString(), data.value("share_with_displayname").toString(), @@ -602,7 +622,7 @@ QSharedPointer ShareManager::parseUserGroupShare(const QJsonObje note)); } -QSharedPointer ShareManager::parseLinkShare(const QJsonObject &data) +QSharedPointer ShareManager::parseLinkShare(const QJsonObject &data) const { QUrl url; diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h index e68620e31..1cb51df46 100644 --- a/src/gui/sharemanager.h +++ b/src/gui/sharemanager.h @@ -440,10 +440,21 @@ public: */ void fetchShares(const QString &path); + /** + * Fetch shares with the current user for path + * + * @param path The path to get the shares for relative to the users folder on the server + * + * On success the sharedWithMeFetched signal is emitted + * In case of a server error the serverError signal is emitted + */ + void fetchSharedWithMe(const QString &path); + signals: void shareCreated(const OCC::SharePtr &share); void linkShareCreated(const QSharedPointer &share); void sharesFetched(const QList &shares); + void sharedWithMeFetched(const QList &shares); void serverError(int code, const QString &message); /** Emitted when creating a link share with password fails. @@ -456,15 +467,17 @@ signals: private slots: void slotSharesFetched(const QJsonDocument &reply); + void slotSharedWithMeFetched(const QJsonDocument &reply); void slotLinkShareCreated(const QJsonDocument &reply); void slotShareCreated(const QJsonDocument &reply); void slotOcsError(int statusCode, const QString &message); void slotCreateE2eeShareJobFinised(int statusCode, const QString &message); private: - QSharedPointer parseLinkShare(const QJsonObject &data); - QSharedPointer parseUserGroupShare(const QJsonObject &data); + QSharedPointer parseLinkShare(const QJsonObject &data) const; + QSharedPointer parseUserGroupShare(const QJsonObject &data) const; SharePtr parseShare(const QJsonObject &data) const; + const QList parseShares(const QJsonDocument &reply) const; AccountPtr _account; };